package com.hontech.bread.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.TextView
import com.hontech.bread.R


class LabelTextView2(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val tvVal: TextView
    private val tvKey: TextView

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_label_text2, this)
        tvVal = view.findViewById(R.id.id_tv_val)
        tvKey = view.findViewById(R.id.id_tv_key)

        val attr = context.obtainStyledAttributes(attrs, R.styleable.LabelTextView2)
        val key = attr.getString(R.styleable.LabelTextView2_lt_k)
        attr.recycle()

        tvKey.text = key
    }

    fun setWidth(width: Int, width2: Int) {
        tvKey.width = width
        tvVal.width = width2
    }

    fun setKey(key: String) {
        tvKey.text = key
    }

    fun set(text: Int) {
        tvVal.text = text.toString()
    }

    fun set(text: String) {
        tvVal.text = text
    }

    fun set(value: Double) {
        tvVal.text = String.format("%.1f", value)
    }

    fun set(value: Float) {
        tvVal.text = String.format("%.1f", value)
    }

    fun setC(value: Float) {
        tvVal.text = "${String.format("%.1f", value)}℃"
    }
}

